home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / gfx / fract / FlashMandelWOS.lha / FlashMandel / Developer / Modules / React / FM_IntegerReq_React.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-03  |  11.9 KB  |  403 lines

  1. /*
  2.  *  FM_IntegerReq_React.c
  3.  *
  4.  *  Requester for cycledelay-request and iterations-request with reaction-support
  5.  *  $VER: V2.0, 13.10.2001
  6.  *  Coded by Edgar Schwan
  7.  */
  8.  
  9. #include <intuition/gadgetclass.h>
  10. #include <intuition/classusr.h>
  11. #include <intuition/screens.h>
  12. #include <classes/window.h>
  13. #include <dos/dos.h>
  14. #include <gadgets/integer.h>
  15.  
  16. #include <clib/intuition_protos.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/graphics_protos.h>
  19. #include <clib/alib_protos.h>
  20.  
  21. #include <pragmas/intuition_pragmas.h>
  22. #include <pragmas/exec_pragmas.h>
  23. #include <pragmas/graphics_pragmas.h>
  24.  
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27.  
  28. #include "FM_IntegerReq_React.h"
  29. #include "FM_ReactionBasics.h"
  30. #include "FM_Reaction.h"
  31. #include "FM_ReactionCD.h"
  32.  
  33. extern ULONG *PALETTE;
  34.  
  35. struct ReactWinData *cycle_rwd = NULL;
  36. struct ReactWinData *iterat_rwd = NULL;
  37.  
  38. /*  Do_CycleDelayRequest(): cycledelay-requester (full handling).
  39.  
  40.         SYNOPSIS: ULONG NewValue = Do_CycleDelayRequest
  41.                         (
  42.                         struct Window     *Win;
  43.                         char                  *PubScreenName;
  44.                         WORD                    Left;
  45.                         WORD                    Top;
  46.                         ULONG                   Value;
  47.                         );
  48.  
  49.         INPUTS:     Win:
  50.                             Pointer to the parent-window.
  51.  
  52.                         PubScreenName:
  53.                             name of the public-screen, where the window should appear.
  54.  
  55.                         Left:
  56.                             Left edge of palette-window.
  57.  
  58.                         Top:
  59.                             Top edge of palette-window.
  60.  
  61.                         Value:
  62.                             Actual value for delay-time.
  63.  
  64.         RETURNS:        NewValue:
  65.                             New value for delay-time.
  66. */
  67.  
  68. ULONG Do_CycleDelayRequest(struct Window *Win, char *PubScreenName, WORD Left, WORD Top, ULONG Value)
  69. {
  70. LONG result = RESULT_NOTHING;
  71. ULONG waitsigs, mask;
  72. ULONG NewValue = Value;
  73.  
  74. if (OpenCycleReqWindow(PubScreenName, Value) == TRUE) {
  75.  
  76.     waitsigs = cycle_rwd->RWD_WSignals|SIGBREAKF_CTRL_C;
  77.  
  78.     while(result == RESULT_NOTHING) {
  79.         mask = Wait(waitsigs);
  80. #ifndef NDEBUG
  81.         printf("mask: %lX\n", mask);
  82. #endif /*NDEBUG*/
  83.         if (mask & cycle_rwd->RWD_WSignals) {
  84.             result = HandleCycleReqWindow(Win, &NewValue);
  85.             if (result == RESULT_CANCEL) NewValue = Value;
  86.             }
  87.         if (mask & SIGBREAKF_CTRL_C) {
  88.             NewValue = Value;
  89.             result = RESULT_CANCEL;
  90.             }
  91.         }
  92.  
  93.     CloseCycleReqWindow();
  94.     } else DisplayError(Win, TXT_ERR_Window, 5L);
  95.  
  96. LoadRGB32(ViewPortAddress (Win), (APTR) PALETTE);
  97. return(NewValue);
  98. }
  99.  
  100. /*  OpenCycleReqWindow(): open window of cycle-requester.
  101.  
  102.         SYNOPSIS: BOOL res = OpenCycleReqWindow
  103.                         (
  104.                         char      *PubScreenName;
  105.                         ULONG       Value;
  106.                         );
  107.  
  108.         INPUTS:     PubScreenName:
  109.                             name of the public-screen, where the window should appear.
  110.  
  111.                         Value:
  112.                             Value for Integer-Gadget.
  113.  
  114.         RETURNS:        res:
  115.                             TRUE, if successfull.
  116. */
  117.  
  118. BOOL OpenCycleReqWindow(char *PubScreenName, ULONG Value)
  119. {
  120. if (cycle_rwd = OpenReactionWindow(WIN_CYC_ID, GROUP_Cyc_ID, PubScreenName)) {
  121.     SetGadgetAttrs(cycle_rwd->RWD_GadgetArray[Cyc_INTEGER_DelayTime], cycle_rwd->RWD_IWindow, NULL,
  122.                         INTEGER_Number, Value, TAG_DONE);
  123.     return(TRUE);
  124.     }
  125. return(FALSE);
  126. }
  127.  
  128. /*  CloseCycleReqWindow(): close window of cycle-requester.
  129.  
  130.         SYNOPSIS: void = CloseCycleReqWindow
  131.                         (
  132.                         void
  133.                         );
  134.  
  135.         INPUTS:     -
  136.  
  137.         RETURNS:        -
  138. */
  139.  
  140. void CloseCycleReqWindow(void)
  141. {
  142. CloseReactionWindow(cycle_rwd);
  143. }
  144.  
  145. /*  HandleCycleReqWindow(): Handle the messages of the cycle-requester.
  146.  
  147.         SYNOPSIS: LONG = HandleCycleReqWindow
  148.                         (
  149.                         struct Window   *Win;
  150.                         ULONG               *NewValue
  151.                         );
  152.  
  153.         INPUTS:     Win:
  154.                             Pointer to a window-structure.
  155.  
  156.                         NewValue:
  157.                             Pointer to a var to store the new value.
  158.  
  159.         RETURNS:        res:
  160.                             result of messages: RESULT_NOTHING -> nothing happens.
  161.                                                         RESULT_CANCEL  -> user wants to quit without a change.
  162.                                                         RESULT_OK      -> accept changes and quit.
  163. */
  164.  
  165. LONG HandleCycleReqWindow(struct Window *Win, ULONG *NewValue)
  166. {
  167. LONG rc = RESULT_NOTHING;
  168. ULONG result, code;
  169.  
  170. while((result = DoMethod(cycle_rwd->RWD_WindowObject, WM_HANDLEINPUT, &code)) != WMHI_LASTMSG) {
  171.  
  172. #ifndef NDEBUG
  173.     printf("result: %ld\n", result);
  174. #endif /*NDEBUG*/
  175.  
  176.     switch (result & WMHI_CLASSMASK) {
  177.         case WMHI_CLOSEWINDOW:
  178.             rc = RESULT_CANCEL;
  179.             break;
  180.  
  181.         case WMHI_GADGETUP:
  182.             switch (result & RL_GADGETMASK) {
  183.                 case Cyc_BUTTON_Accept:
  184.                     rc = RESULT_OK;
  185.                     break;
  186.                 case Cyc_BUTTON_Cancel:
  187.                     rc = RESULT_CANCEL;
  188.                     break;
  189.                 case Cyc_INTEGER_DelayTime:
  190.                     GetAttr(INTEGER_Number, cycle_rwd->RWD_GadgetArray[Cyc_INTEGER_DelayTime], NewValue);
  191.                     break;
  192. #ifndef NDEBUG
  193.                 default:
  194.                     printf("unknown result: %lX\nunknown gadget: %lX\n", result, result & WMHI_GADGETMASK);
  195.                     DisplayBeep(NULL);
  196.                     break;
  197. #endif /*NDEBUG*/
  198.                 }
  199.             break;
  200.  
  201.         case WMHI_ICONIFY:
  202.             DoMethod(cycle_rwd->RWD_WindowObject, WM_ICONIFY);
  203.             GetAttr(WINDOW_Window, cycle_rwd->RWD_WindowObject, (ULONG *) &cycle_rwd->RWD_IWindow);
  204.             break;
  205.  
  206.         case WMHI_UNICONIFY:
  207.             DoMethod(cycle_rwd->RWD_WindowObject, WM_OPEN);
  208.             GetAttr(WINDOW_Window, cycle_rwd->RWD_WindowObject, (ULONG *) &cycle_rwd->RWD_IWindow);
  209.             break;
  210. #ifndef NDEBUG
  211.         default:
  212.             printf("unknown result: %lX\nunknown class: %lX\n", result, result & WMHI_CLASSMASK);
  213.             DisplayBeep(NULL);
  214.             break;
  215. #endif /*NDEBUG*/
  216.         }
  217.     }
  218. return(rc);
  219. }
  220.  
  221. /*  Do_IterationsRequest(): iteration-requester (full handling).
  222.  
  223.         SYNOPSIS: ULONG NewValue = Do_IterationsRequest
  224.                         (
  225.                         struct Window     *Win;
  226.                         char                  *PubScreenName;
  227.                         WORD                    Left;
  228.                         WORD                    Top;
  229.                         ULONG                   Value;
  230.                         );
  231.  
  232.         INPUTS:     Win:
  233.                             Pointer to the parent-window.
  234.  
  235.                         PubScreenName:
  236.                             name of the public-screen, where the window should appear.
  237.  
  238.                         Left:
  239.                             Left edge of palette-window.
  240.  
  241.                         Top:
  242.                             Top edge of palette-window.
  243.  
  244.                         Value:
  245.                             Actual value for delay-time.
  246.  
  247.         RETURNS:        NewValue:
  248.                             New value for delay-time.
  249. */
  250.  
  251. ULONG Do_IterationsRequest(struct Window *Win, char *PubScreenName, WORD Left, WORD Top, ULONG Value)
  252. {
  253. LONG result = RESULT_NOTHING;
  254. ULONG waitsigs, mask;
  255. ULONG NewValue = Value;
  256.  
  257. if (OpenIteratReqWindow(PubScreenName, Value) == TRUE) {
  258.  
  259.     waitsigs = iterat_rwd->RWD_WSignals|SIGBREAKF_CTRL_C;
  260.  
  261.     while(result == RESULT_NOTHING) {
  262.         mask = Wait(waitsigs);
  263. #ifndef NDEBUG
  264.         printf("mask: %lX\n", mask);
  265. #endif /*NDEBUG*/
  266.         if (mask & iterat_rwd->RWD_WSignals) {
  267.             result = HandleIteratReqWindow(Win, &NewValue);
  268.             if (result == RESULT_CANCEL) NewValue = Value;
  269.             }
  270.         if (mask & SIGBREAKF_CTRL_C) {
  271.             NewValue = Value;
  272.             result = RESULT_CANCEL;
  273.             }
  274.         }
  275.  
  276.     CloseIteratReqWindow();
  277.     } else DisplayError(Win, TXT_ERR_Window, 5L);
  278.  
  279. LoadRGB32(ViewPortAddress (Win), (APTR) PALETTE);
  280. return(NewValue);
  281. }
  282.  
  283. /*  OpenIteratReqWindow(): open window of iteration-requester.
  284.  
  285.         SYNOPSIS: BOOL res = OpenIteratReqWindow
  286.                         (
  287.                         char      *PubScreenName;
  288.                         ULONG       Value;
  289.                         );
  290.  
  291.         INPUTS:     PubScreenName:
  292.                             name of the public-screen, where the window should appear.
  293.  
  294.                         Value:
  295.                             Value for integer-gadget.
  296.  
  297.         RETURNS:        res:
  298.                             TRUE, if successfull.
  299. */
  300.  
  301. BOOL OpenIteratReqWindow(char *PubScreenName, ULONG Value)
  302. {
  303. if (iterat_rwd = OpenReactionWindow(WIN_IT_ID, GROUP_It_ID, PubScreenName)) {
  304.     SetGadgetAttrs(iterat_rwd->RWD_GadgetArray[It_INTEGER_Iterations], iterat_rwd->RWD_IWindow, NULL,
  305.                         INTEGER_Number, Value, TAG_DONE);
  306.     return(TRUE);
  307.     }
  308. return(FALSE);
  309. }
  310.  
  311. /*  CloseIteratReqWindow(): close window of iteration-requester.
  312.  
  313.         SYNOPSIS: void = CloseIteratReqWindow
  314.                         (
  315.                         void
  316.                         );
  317.  
  318.         INPUTS:     -
  319.  
  320.         RETURNS:        -
  321. */
  322.  
  323. void CloseIteratReqWindow(void)
  324. {
  325. CloseReactionWindow(iterat_rwd);
  326. }
  327.  
  328. /*  HandleIteratReqWindow(): Handle the messages of the iteration-requester.
  329.  
  330.         SYNOPSIS: LONG = HandleIteratReqWindow
  331.                         (
  332.                         struct Window   *Win;
  333.                         ULONG               *NewValue
  334.                         );
  335.  
  336.         INPUTS:     Win:
  337.                             Pointer to a window-structure.
  338.  
  339.                         NewValue:
  340.                             Pointer to a var to store the new value.
  341.  
  342.         RETURNS:        res:
  343.                             result of messages: RESULT_NOTHING -> nothing happens.
  344.                                                         RESULT_CANCEL  -> user wants to quit without a change.
  345.                                                         RESULT_OK      -> accept changes and quit.
  346. */
  347.  
  348. LONG HandleIteratReqWindow(struct Window *Win, ULONG *NewValue)
  349. {
  350. LONG rc = RESULT_NOTHING;
  351. ULONG result, code;
  352.  
  353. while((result = DoMethod(iterat_rwd->RWD_WindowObject, WM_HANDLEINPUT, &code)) != WMHI_LASTMSG) {
  354.  
  355. #ifndef NDEBUG
  356.     printf("result: %ld\n", result);
  357. #endif /*NDEBUG*/
  358.  
  359.     switch (result & WMHI_CLASSMASK) {
  360.         case WMHI_CLOSEWINDOW:
  361.             rc = RESULT_CANCEL;
  362.             break;
  363.  
  364.         case WMHI_GADGETUP:
  365.             switch (result & RL_GADGETMASK) {
  366.                 case It_BUTTON_Accept:
  367.                     rc = RESULT_OK;
  368.                     break;
  369.                 case It_BUTTON_Cancel:
  370.                     rc = RESULT_CANCEL;
  371.                     break;
  372.                 case It_INTEGER_Iterations:
  373.                     GetAttr(INTEGER_Number, iterat_rwd->RWD_GadgetArray[It_INTEGER_Iterations],NewValue);
  374.                     break;
  375. #ifndef NDEBUG
  376.                 default:
  377.                     printf("unknown result: %lX\nunknown gadget: %lX\n", result, result & WMHI_GADGETMASK);
  378.                     DisplayBeep(NULL);
  379.                     break;
  380. #endif /*NDEBUG*/
  381.                 }
  382.             break;
  383.  
  384.         case WMHI_ICONIFY:
  385.             DoMethod(iterat_rwd->RWD_WindowObject, WM_ICONIFY);
  386.             GetAttr(WINDOW_Window, iterat_rwd->RWD_WindowObject, (ULONG *) &iterat_rwd->RWD_IWindow);
  387.             break;
  388.  
  389.         case WMHI_UNICONIFY:
  390.             DoMethod(iterat_rwd->RWD_WindowObject, WM_OPEN);
  391.             GetAttr(WINDOW_Window, iterat_rwd->RWD_WindowObject, (ULONG *) &iterat_rwd->RWD_IWindow);
  392.             break;
  393. #ifndef NDEBUG
  394.         default:
  395.             printf("unknown result: %lX\nunknown class: %lX\n", result, result & WMHI_CLASSMASK);
  396.             DisplayBeep(NULL);
  397.             break;
  398. #endif /*NDEBUG*/
  399.         }
  400.     }
  401. return(rc);
  402. }
  403.